# Title     : TODO
# Objective : TODO
# Created by: yz
# Created on: 2018/6/8
library(optparse)
library(magrittr)
library(tidyr)
library(tibble)
library(tidyverse)

option_list <- list(
  make_option("--t", type = 'character', action = "store", default = "Metabolite", help = "input metabolite ID type"),
  make_option("--base", default = "metabo_base.R", type = "character", help = "metabo base R file")
)
opt <- parse_args(OptionParser(option_list = option_list))

source(opt$base)
diffData <- read_csv("../../potential/Markers.csv")

if (nrow(diffData) == 0) {
  quit(status = 0)
}

diffKeggs <- diffData %>%
  .$KEGG %>%
  map(function(x) {
    str_split(x, "/") %>% unlist()
  }) %>%
  flatten_chr()
diffKeggs

nm.mat <- diffData %>%
  mutate(query = KEGG, kegg = KEGG, hmdb = Metabolite,hmdbid=HMDB) %>%
  select(c("query","hmdb","kegg","hmdbid"))

cmpd.vec <- diffKeggs
mSet <- InitDataObjects("conc", "msetora", FALSE)
mSet <- Setup.MapData(mSet, nm.mat)
mSet <- CrossReferencing(mSet, "kegg")
save(mSet, file = "idMapping_mSet.RData")

